// pages/inpram/cl/bigprescription/bigprescription.js
import { $wuxCalendar } from '../../../../dist/index'
// import ad from '../../../index/ad'
const network = require('../../../../utils/network.js')




Page({
  data: {
    value1: ['2020-01-01'],
    value2: ['2020-01-30'],
    value3: '',
    value4: [],
    value5: '',
    pram_cataAmount:100,
    //选择科室之后的参数
    dept_select: false,
    pram_dept: {
      deptid: '',
      deptcode: '',
      deptname: ''
    },

    //选择处方类型之后的参数
    cata_select: false,
    pram_cata: {
      cataid: '',
      catacode: '',
      cataname: ''
    },

    //选择医生之后的参数
    doctor_select: false,
    pram_doctor: {
      doctorid: '',
      doctorcode: '',
      doctorname: ''
    },

    //网络请求获取的参数List与下标
    dept_list: [],
    dept_index: 0,

    cata_list:[
    ],
    cata_index: 0,

    doctor_list:[
    ],
    doctor_index: 0,

  },

  /**
    * 生命周期函数--监听页面加载
    */
  onLoad: function (options) {
    var that = this
    //调用网络请求
    that.myRequest()

  },

  myRequest: function () {
    var that = this
    //调用封装好的网络请求，获取数据
    network.get('/utils/cataInPram', {}
    ).then(function (res) {
      console.log('res:', res)
      var obj1 = res.data.data
      var obj2 = res.data.data_2
      var obj3 = res.data.data_3
      that.setData({
        'cata_list': obj1,
        'dept_list': obj2,
        'doctor_list': obj3
      })
    }).then(function (res) {

    }).catch(function (res) {
      console.log(res)
    })
  },


  openCalendar1() {
    $wuxCalendar().open({
      value: this.data.value1,
      onChange: (values, displayValues) => {
        console.log('onChange', values, displayValues)
        this.setData({
          value1: displayValues,
        })
      },
    })
  },
  openCalendar2() {
    $wuxCalendar().open({
      value: this.data.value2,
      // multiple: true,
      onChange: (values, displayValues) => {
        console.log('onChange', values, displayValues)
        this.setData({
          value2: displayValues,
        })
      },
    })
  },
  onChange(e) {
    console.log('onChange', e)
    this.setData({
      
      pram_cataAmount: e.detail.value
    })
  },
//获取input的取值
  getAmount: function (e) {
    var that = this;
    console.log("e:", e);
    that.setData({
      pram_cataAmount: e.detail.value
     
    })
    console.log("pram_cataAmount:", that.data.pram_cataAmount);
  },

//这个函数一定要写在标签上才能用e.detail.value获取到
  bindPickerChange_cata: function (e) {
    let that = this;
    var nowData = [];
    nowData = that.properties.cata_list;//当前option的数据是引入组件的页面传过来的，所以这里获取数据只有通过this.properties
    var nowIdx = e.target.dataset.index;//当前点击的索引
    // var nowText = nowData[nowIdx].text;//当前点击的内容
    //console.log('picker数组为', nowData);
    //console.log('picker发送选择改变，携带值为', e.detail.value);
    that.setData({   //给变量赋值
      //dept_index: e.detail.value,  //每次选择了下拉列表的内容同时修改下标然后修改显示的内容，显示的内容和选择的内容一致
      // cata_select: true
      'pram_cata.cataid': nowData[e.detail.value].cataId,
      'pram_cata.catacode': nowData[e.detail.value].cataCode,
      'pram_cata.cataname': nowData[e.detail.value].cataName

    })
    console.log('自定义值:', that.properties.pram_cata);
  },

  bindPickerChange_dept: function (e) {
    let that = this;
    var nowData = [];
    nowData = that.properties.dept_list;//当前option的数据是引入组件的页面传过来的，所以这里获取数据只有通过this.properties
    var nowIdx = e.target.dataset.index;//当前点击的索引
    // var nowText = nowData[nowIdx].text;//当前点击的内容
    //console.log('picker数组为', nowData);
    //console.log('picker发送选择改变，携带值为', e.detail.value);
    that.setData({   //给变量赋值
      //dept_index: e.detail.value,  //每次选择了下拉列表的内容同时修改下标然后修改显示的内容，显示的内容和选择的内容一致
      dept_select: true,
      'pram_dept.deptid': nowData[e.detail.value].deptId,
      'pram_dept.deptcode': nowData[e.detail.value].deptCode,
      'pram_dept.deptname': nowData[e.detail.value].deptName

    })
    console.log('自定义值:', that.properties.pram_dept);
  },


  bindPickerChange_doctor: function (e) {
    let that = this;
    var nowData = [];
    nowData = that.properties.doctor_list;//当前option的数据是引入组件的页面传过来的，所以这里获取数据只有通过this.properties
    var nowIdx = e.target.dataset.index;//当前点击的索引
    // var nowText = nowData[nowIdx].text;//当前点击的内容
    //console.log('picker数组为', nowData);
    //console.log('picker发送选择改变，携带值为', e.detail.value);
    that.setData({   //给变量赋值
      //dept_index: e.detail.value,  //每次选择了下拉列表的内容同时修改下标然后修改显示的内容，显示的内容和选择的内容一致
      doctor_select: true,
      'pram_doctor.doctorid': nowData[e.detail.value].userId,
      'pram_doctor.doctorcode': nowData[e.detail.value].userCode,
      'pram_doctor.doctorname': nowData[e.detail.value].userName

    })
    console.log('自定义值:', that.properties.pram_doctor);
  },
  // 时间比较函数
  compareDate: function (startDate, endDate) {
    var arrStart = startDate.split("-");
    var startTime = new Date(arrStart[0], arrStart[1], arrStart[2]);
    var startTimes = startTime.getTime();
    var arrEnd = endDate.split("-");
    var endTime = new Date(arrEnd[0], arrEnd[1], arrEnd[2]);
    var endTimes = endTime.getTime();
    // console.log('startTimes', startTimes);
    // console.log('endTimes', endTimes);
    if (endTimes <= startTimes) {
      return false;
    }
    return true;
  },
  determine: function (e) {
    var that = this
    var day = that.compareDate(that.data.value1[0], that.data.value2[0]);
    //that.getAmount(e);
    console.log('day', day);
    if (!day) {
      wx.showModal({

        title: '提示',

        content: '开始时间必须小于结束时间一天',

      })

    } else {
      wx.redirectTo({
        url: '../../../view/cl/bigprescription/bigprescription?startTime=' + this.data.value1[0] + '&endTime=' + this.data.value2[0] + '&cataAmount=' + that.data.pram_cataAmount + '&deptId=' + that.data.pram_dept.deptid + '&cataId=' + that.data.pram_cata.cataid + '&doctorId=' + that.data.pram_doctor.doctorid
      })
    }
  },

})

// Page({

//   /**
//    * 页面的初始数据
//    */
//   data: {
//     value1: [],
//     pram_startTime: '2020-01-01',
//     pram_endTime: '2020-01-30',

//     //输入处方金额
//     hiddenmodalput: true,
//     pram_cataAmount: 100,
//     amount_select:true,

//     //选择科室之后的参数
//     dept_select: false,
//     pram_dept: {
//       deptid: '',
//       deptcode: '',
//       deptname: ''
//     },

//     //选择处方类型之后的参数
//     cata_select: false,
//     pram_cata: {
//       cataid: '',
//       catacode: '',
//       cataname: ''
//     },

//     //选择医生之后的参数
//     doctor_select: false,
//     pram_doctor: {
//       doctorid: '',
//       doctorcode: '',
//       doctorname: ''
//     },

//     //网络请求获取的参数List与下标
//     dept_list: [],
//     dept_index: 0,

//     cata_list:[
//     ],
//     cata_index: 0,

//     doctor_list:[
//     ],
//     doctor_index: 0,

//   },
//   openCalendar1() {
//     $wuxCalendar().open({
//       value: this.data.value1,
//       onChange: (values, displayValues) => {
//         console.log('onChange', values, displayValues)
//         this.setData({
//           value1: displayValues,
//         })
//       },
//     })
//   },
//   /**
//    * 生命周期函数--监听页面加载
//    */
//   onLoad: function (options) {
//     var that = this
//     //调用封装好的网络请求，获取数据
//     network.get('/utils/cataInPram', {}
//     ).then(function (res) {
//       console.log('res:', res)
//       var obj1 = res.data.data
//       var obj2 = res.data.data_2
//       var obj3 = res.data.data_3
//       that.setData({
//         'cata_list': obj1,
//         'dept_list': obj2,
//         'doctor_list': obj3
//       })
//     }).then(function (res) {

//     }).catch(function (res) {
//       console.log(res)
//     })


//   },


//   // 开始时间选择  
//   bindDateChange_start(e) {
//     let that = this;
//     console.log(e.detail.value)
//     that.setData({
//       pram_startTime: e.detail.value

//     })
//   },

//   // 结束时间选择  
//   bindDateChange_end(e) {
//     let that = this;
//     console.log(e.detail.value)
//     that.setData({

//       pram_endTime: e.detail.value
//     })
//   },

//   //点击按钮痰喘指定的hiddenmodalput弹出框

//   modalinput: function (e) {
   
//     this.setData({
//       hiddenmodalput: !this.data.hiddenmodalput

//     })

//   },

//   cataAmount: function(e){
//     //console.log('pram_cataAmount:e.detail.value', e.detail.value)
//     this.setData({
//       pram_cataAmount: e.detail.value,
//     })
//   },
//   //取消按钮

//   cancel: function () {

//     this.setData({
    
//       hiddenmodalput: true

//     });

//   },

//   //确认

//   confirm: function (e) {
    
//     console.log('event',e.target.dataset)
//     this.setData({
//       amount_select: true,
//       hiddenmodalput: true

//     })

//   },

//   bindPickerChange_cata: function (e) {
//     let that = this;
//     var nowData = [];
//     nowData = that.properties.cata_list;//当前option的数据是引入组件的页面传过来的，所以这里获取数据只有通过this.properties
//     var nowIdx = e.target.dataset.index;//当前点击的索引
//     // var nowText = nowData[nowIdx].text;//当前点击的内容
//     //console.log('picker数组为', nowData);
//     //console.log('picker发送选择改变，携带值为', e.detail.value);
//     that.setData({   //给变量赋值
//       //dept_index: e.detail.value,  //每次选择了下拉列表的内容同时修改下标然后修改显示的内容，显示的内容和选择的内容一致
//       cata_select: true,
//       'pram_cata.cataid': nowData[e.detail.value].cataId,
//       'pram_cata.catacode': nowData[e.detail.value].cataCode,
//       'pram_cata.cataname': nowData[e.detail.value].cataName

//     })
//     console.log('自定义值:', that.properties.pram_cata);
//   },

//   bindPickerChange_dept: function (e) {
//     let that = this;
//     var nowData = [];
//     nowData = that.properties.dept_list;//当前option的数据是引入组件的页面传过来的，所以这里获取数据只有通过this.properties
//     var nowIdx = e.target.dataset.index;//当前点击的索引
//     // var nowText = nowData[nowIdx].text;//当前点击的内容
//     //console.log('picker数组为', nowData);
//     //console.log('picker发送选择改变，携带值为', e.detail.value);
//     that.setData({   //给变量赋值
//       //dept_index: e.detail.value,  //每次选择了下拉列表的内容同时修改下标然后修改显示的内容，显示的内容和选择的内容一致
//       dept_select: true,
//       'pram_dept.deptid': nowData[e.detail.value].deptId,
//       'pram_dept.deptcode': nowData[e.detail.value].deptCode,
//       'pram_dept.deptname': nowData[e.detail.value].deptName

//     })
//     console.log('自定义值:', that.properties.pram_dept);
//   },


//   bindPickerChange_doctor: function (e) {
//     let that = this;
//     var nowData = [];
//     nowData = that.properties.doctor_list;//当前option的数据是引入组件的页面传过来的，所以这里获取数据只有通过this.properties
//     var nowIdx = e.target.dataset.index;//当前点击的索引
//     // var nowText = nowData[nowIdx].text;//当前点击的内容
//     //console.log('picker数组为', nowData);
//     //console.log('picker发送选择改变，携带值为', e.detail.value);
//     that.setData({   //给变量赋值
//       //dept_index: e.detail.value,  //每次选择了下拉列表的内容同时修改下标然后修改显示的内容，显示的内容和选择的内容一致
//       doctor_select: true,
//       'pram_doctor.doctorid': nowData[e.detail.value].userId,
//       'pram_doctor.doctorcode': nowData[e.detail.value].userCode,
//       'pram_doctor.doctorname': nowData[e.detail.value].userName

//     })
//     console.log('自定义值:', that.properties.pram_doctor);
//   },
//   // 时间比较函数
//   compareDate: function (startDate, endDate) {
//     var arrStart = startDate.split("-");
//     var startTime = new Date(arrStart[0], arrStart[1], arrStart[2]);
//     var startTimes = startTime.getTime();
//     var arrEnd = endDate.split("-");
//     var endTime = new Date(arrEnd[0], arrEnd[1], arrEnd[2]);
//     var endTimes = endTime.getTime();
//     // console.log('startTimes', startTimes);
//     // console.log('endTimes', endTimes);
//     if (endTimes <= startTimes) {
//       return false;
//     }
//     return true;
//   },
//   determine: function () {
//     var that = this
//     var day = that.compareDate(that.data.pram_startTime, that.data.pram_endTime);
//     console.log('day', day)
//     if (!day) {
//       wx.showModal({

//         title: '提示',

//         content: '开始时间必须小于结束时间一天',

//       })

//     } else {
//     wx.redirectTo({
//       url: '../../../view/cl/bigprescription/bigprescription?startTime=' + this.data.pram_startTime + '&endTime=' + this.data.pram_endTime + '&cataAmount=' + that.data.pram_cataAmount + '&deptId=' + that.data.pram_dept.deptid + '&cataId=' + that.data.pram_cata.cataid + '&doctorId=' + that.data.pram_doctor.doctorid
//     })
//     }
//   },
//   cancel: function () {
//     wx.navigateBack({ changed: true });
//   }
// })